package com.example.rocketmq.delay;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

/**
 * 延迟发送消息
 * 
 */
public class DelayProducer {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("test_group");
        producer.setNamesrvAddr("192.168.228.101:9876");
        producer.start();
        Message message = new Message("delay_topic", "*", "delay msg".getBytes());
        // 设置延迟级别
        message.setDelayTimeLevel(2);
        SendResult result = producer.send(message);
        System.out.println(result);
        producer.shutdown();
    }
}
